@extends('layouts.frontend-iframe-base')


@section('css')
    <link rel="stylesheet" href="/dist/home/css/add-station.css">
@stop

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        气象站
        <small>修改气象检测站点</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li class="active">首页</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <!-- Your Page Content Here -->
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">修改气象检测站点</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form class="form-horizontal" id="J-form">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">设备名称</label>

                            <div class="col-sm-10">
                                <input id ='name_1' name="devicename" type="text" class="form-control" value ={{$ms->name}} placeholder={{$ms->name}}>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">设备监测方向</label>

                            <div class="col-sm-10">
                                <input  id = 'dir_1' name="direction" type="text" class="form-control" value = {{$ms->direction}} placeholder={{$ms->direction}}>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">备注</label>

                            <div class="col-sm-10">
                                <input id = 'remarks_1' name="remarks" type="text" class="form-control" value ={{$ms->remarks}}  placeholder="{{$ms->remarks}}">
                            </div>
                        </div>
                            <input id = 'hidden-id' type="hidden" value={{$ms->id}}>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">添加逆变器</label>
                            <div class="cententi">
                                <div class="cententl">
                                    <select multiple="multiple" id="select1" style="width: 150px; height: 200px;">
                                        @if(count($unchecks)>0)
                                        @foreach($unchecks as $uncheck )
                                        <option value= {{$uncheck['id']}}>逆变器{{$uncheck['name']}}</option>
                                        @endforeach
                                        @endif
                                    </select>
                                </div>
                                <div class="btnAdd">
                                    <input type="button" id="btnAdd" value=" > " /><br />
                                    <input type="button" id="btnDel" value=" < " /><br />
                                    <input type="button" id="btnAdds" value=">>" /><br />
                                    <input type="button" id="btnDels" value="<<" />
                                </div>
                                <div>
                                    <select  multiple="multiple" id="select2" style="width: 150px; height: 200px;">
                                    @if(count($checks)>0)
                                        @foreach($checks as $check )
                                            <option value= {{$check['id']}}>逆变器{{$check['name']}}</option>
                                        @endforeach
                                    @endif
                                    </select>
                                </div>
                            </div>
                            {{--<div class="col-sm-10">--}}
                                {{--<input name="remarks" type="text" class="form-control" placeholder="哪些逆变器">--}}
                            {{--</div>--}}
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button id ='submit1'  type="button" class="btn btn-info">提交</button>
                    </div>
                    <!-- /.box-footer -->
                </form>
            </div>

        </div>
    </div>

</section>
<!-- /.content -->


@stop

@section('js')
        <script type="text/javascript">
            $(function () {
                //移到右边
                $('#btnAdd').click(function () {
                    //获取选中的选项，删除自己并追加给对方
                    $('#select1 option:selected').appendTo('#select2');
                });
                //移到左边
                $('#btnDel').click(function () {
                    //获取选中的选项，删除自己并追加给对方
                    $('#select2 option:selected').appendTo('#select1');
                });
                //全部移到右边
                $('#btnAdds').click(function () {
                    //获取全部的选项,删除自己并追加给对方
                    $('#select1 option').appendTo('#select2');
                });
                //全部移到左边
                $('#btnDels').click(function () {
                    //获取全部的选项,删除自己并追加给对方
                    $('#select2 option').appendTo('#select1');
                });
                //双击选项
                $('#select1').dblclick(function () {
                    //获取双击的选项,删除自己并追加给对方
                    $("option:selected", this).appendTo('#select2');
                });
                //双击选项
                $('#select2').dblclick(function () {
                    //获取双击的选项,删除自己并追加给对方
                    $("option:selected", this).appendTo('#select1');
                });
            });
    </script>
        <script>
            $(function () {
//                var devicename = $('name_1').val;
//                var dir_1 = $('dir_1').val;
//                var remarks_1 = $('remarks_1').val;
//                var devices = $('#select2').val;
//                $.post("/frontend/weather/create-station",{'name':devicename,'direction':dir_1,'remarks':remarks_1,'devices':devices},function (data) {
//                        console.log(data);
//                })
//            })

                $('#submit1').click(function () {
                    var id = $('#hidden-id').val();
                    var devicename = $('#name_1').val();
                    var dir_1 = $('#dir_1').val();
                    var remarks_1 = $('#remarks_1').val();
                    var array = new Array();  //定义数组
                    $("#select2 option").each(function() {  //遍历所有option
                        var txt = $(this).val();   //获取option值
                        if (txt != '') {
                            array.push(txt);  //添加到数组中
                        }
                    });

                    $.post('/frontend/weather/update-station',{'id':id,'name':devicename,'direction':dir_1,'remarks':remarks_1,'devices':array},function (data) {
                        if(data.status == 1){
                            alert('成功');
                            window.location.href="/frontend/weather/show";
                        }else{
                            alert('失败');
                        }
                    })
                })
            });

//            $("#submit1").click(function() {
//                var devicename = $('#name_1').val;
//                var dir_1 = $('#dir_1').val;
//                var remarks_1 = $('#remarks_1').val;
//                var devices = $('#select2').val;
//                alert(devicename);
////                $.post("/frontend/weather/create-station", {
////                    'name': devicename,
////                    'direction': dir_1,
////                    'remarks': remarks_1,
////                    'devices': devices
////                }, function (data) {
////                    console.log(data);
////                })
//            });
        </script>
    {{--<script>--}}
        {{--$(function () {--}}

            {{--$('#J-form').ajaxForm({--}}
                {{--beforeSubmit:function (data) {--}}
                    {{--for(var i=1;i <= data.length;i++){--}}
{{--//                        alert(data[i]);--}}
                      {{--console.log(data[i]);--}}
                    {{--}--}}
                {{--},--}}
{{--//                beforeSubmit: function (data) {--}}
{{--//                    console.log(data);--}}
{{--//                    for(var i=3;i < length(data);i++){--}}
{{--//--}}
{{--//                    }--}}
{{--////                    if (data[1].value != data[2].value) {--}}
{{--////                        alert('两次密码不一致！');--}}
{{--////                        return false;--}}
{{--////                    }--}}
{{--////                    validator_info_clear($('#J-form'));--}}
{{--//                },--}}
                {{--success: function (data) {--}}
{{--//                    console.log(data);--}}
                    {{--if (data.status == 1) {--}}
                        {{--alert('添加成功');--}}
                        {{--validator_info_clear($('#J-form'));--}}
{{--//                        window.location.href = '/frontend/user/profile';--}}
                    {{--} else {--}}
                        {{--alert(data.error_msg);--}}
                    {{--}--}}
                {{--},--}}
                {{--error: function (xhr) {--}}
                    {{--validator_info_show($('#J-form'), xhr);--}}
                {{--}--}}
            {{--});--}}
        {{--});--}}


    {{--</script>--}}
@stop